package com.himiotech.core.project.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.himiotech.core.project.data.mapper.NoticeMapper;
import com.himiotech.core.project.model.entity.Notice;
import com.himiotech.core.project.model.metadata.NoticeMetadata;
import com.himiotech.core.project.service.INoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


/**
 * 通知公告表 服务层 service
 *
 * @author wuwenbin
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class NoticeServiceImpl extends ServiceImpl<NoticeMapper, Notice> implements INoticeService {

    @Autowired
    private NoticeMapper noticeMapper;

    /**
     * 查询分页数据
     *
     * @param page   分页信息
     * @param notice 业务信息查询条件
     * @return 分页对象及数据
     */
    @Override
    public Page<Notice> selectNoticeListPage(Page<Notice> page, Notice notice) {
        QueryWrapper<Notice> query = Wrappers.query();
        query.eq(ObjectUtil.isNotEmpty(notice.getNoticeTitle()), NoticeMetadata.NOTICE_TITLE.getColName(), notice.getNoticeTitle());
        query.eq(ObjectUtil.isNotEmpty(notice.getNoticeType()), NoticeMetadata.NOTICE_TYPE.getColName(), notice.getNoticeType());
        query.like(ObjectUtil.isNotEmpty(notice.getCreateByName()), NoticeMetadata.CREATE_BY_NAME.getColName(), notice.getCreateByName());
        page = noticeMapper.selectPage(page, query);
        return page;
    }

}
